#!/bin/bash

opt=$1
target_files=~/tmp/log/wpp.log*

#day_str="2 days ago"
day_str="now"
#mon_str="1 month ago"
mon_str="now"

day_end=`date -d "$day_str" "+%d"`
if [ "$opt" == "today" ]; then
	#just for today.
	day_start=$day_end
    date_today=`date +%Y-%m-%d`
    target_files=`ls $target_files -tr --full-time |grep $date_today |awk '{print $NF}'`
else
	#from the beginning of this month.
	day_start=1         
fi

date_mon=`date -d "$mon_str" "+%m"`
date_year=`date +%Y`

for day in $(seq $day_start $day_end)
do
    d=`printf "%02d" $day`
    date_tmp="$date_year-$date_mon-$d"
    hits=`grep -nr 'PosReq' $target_files |grep "$date_tmp" |wc -l` 
    day_of_week=`date -d "$date_tmp" +%u`
    printf '%-10s_%s,%8d\n' $date_tmp $day_of_week $hits
done
